package com.example.demo.service;

import com.example.demo.mapper.MessageMapper;
import com.example.demo.model.MessageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class MessageService {
    @Autowired
    private MessageMapper messageMapper;
    
    public boolean addMessage(MessageInfo message) {
        return messageMapper.insertMessage(message) > 0;
    }
    
    public List<MessageInfo> getProductMessages(Integer pid) {
        return messageMapper.getMessagesByProductId(pid);
    }
    
    public List<MessageInfo> getReceivedMessages(Integer receiverId) {
        return messageMapper.getMessagesByReceiverId(receiverId);
    }
    
    public boolean updateMessageStatus(Integer id, Integer status) {
        return messageMapper.updateMessageStatus(id, status) > 0;
    }
    
    public boolean markAsRead(Integer id) {
        return messageMapper.updateReadStatus(id, 1) > 0;
    }
} 